#include <stdio.h>
#define ROE 3
#define COLUMN 3
#define true 1
#define false  0
void initbord(char (*board)[COLUMN])
{
    for(int i=0;i<ROE;i++)
        for(int j=0;j<COLUMN;j++)

        {
            board[i][j]=' ';
        }
}
void printboard(char (*board)[COLUMN])
{
    printf("\n");
    for(int i=0;i<ROE;i++)
    {
        for(int j=0;j<COLUMN;j++)
        {
            printf("%c ",board[i][j]);
            if(j<COLUMN-1)
                printf("|");
        }
        printf("\n");
        if(i<ROE-1)
            printf("--|--|--\n");
    }
}
int makemove(char (*board)[COLUMN],int row,int colum,char player)
{
    if(row < 0 || row >= ROE || colum < 0 || colum >= COLUMN)
    {
        printf("invald place!please try again!\n");
        return false;
    }
    if(board[row][colum]!=' ')
    {
        printf("this place have no place!try again!\n");
        return false;
    }
    
    board[row][colum]=player;
    return true;

}
int victoryboard(char (*board)[COLUMN],char player)
{
    for(int i=0;i<ROE;i++)
    {
        if(board[i][0]==player&&board[i][1]==player&&board[i][2]==player)
            return true;
    }
    for(int i=0;i<COLUMN;i++)
    {
        if(board[0][i]==player&&board[1][i]==player&&board[2][i]==player)
            return true;
    }
    if(board[0][0]==player&&board[1][1]==player&&board[2][2]==player)
            return true;
    if(board[0][2]==player&&board[1][1]==player&&board[2][0]==player)
            return true;

}
int checkisdraw(char (*board)[COLUMN])
{
    for(int i=0;i<ROE;i++)
    {
        for(int j=0;j<COLUMN;j++)
        {
            if(board[i][j]==' ')
                return false;
        }
    }
    return true;
}

int main(int argc,char *argv[])
{
    char board[ROE][COLUMN]={0};
    initbord(board);
    char player='X';
    while(1)
    {
        printboard(board);
        int row=0,colum=0;
        printf("please %c input a place to mae move:",player);
        scanf("%d %d",&row,&colum);
        if(makemove(board,row-1,colum-1,player)==false)
        {
            continue;
        }
        if(victoryboard(board,player)== true)
        {
            printboard(board);
            printf("player %c victory\n",player);
            break;
        }
        if(checkisdraw(board)==true)
        {
            printboard(board);
            printf("draw game over\n");
            break;
        }
        player=((player)=='X'?'O':'X');
    }
    return 0;
}